home *** CD-ROM | disk | FTP | other *** search
- /*
- * lib Method SX : skelton
- *
- * Author : D.N kit.iizuka
- * Created: 1994 1/12(Wed)
- */
-
- #include <stdio.h>
- #include <method\Task_i.h>
- #include <method\Dialog_i.h>
- #include <method\Memory_i.h>
- #include <method\Graph_i.h>
- #include <method/Window_i.h>
- #include <method\methodSx.h>
- #include <method\Dos_i.h>
- #include <method\sxutil.h>
-
- #define SXVERSION 0x300 /* SXのバージョンチェックをしない場合は外す */
-
- #define MAIN_DX 256 /* メインウインドウの横幅 */
- #define MAIN_DY 200 /* メインウインドウの縦幅 */
- #define MAIN_ID 32 /* メインウインドウの種類 */
- #define MAIN_OPT 0 /* メインウインドウの付属品 */
-
- /*
- * 関数宣言
- */
- int MainDraw();
-
- unsigned int conv_hex( unsigned int );
- int showgraph( unsigned short , unsigned short , unsigned int );
- int search_graphicindex( unsigned int );
- int MultiMouse(void);
- int DispPrev( void );
- int DispNext( void );
-
-
- int cdfile;
- rectImg *ri; /* レクタングルイメージへのポインタ */
- unsigned short gra_x = 256; /* kenji suzuki */
- unsigned short gra_y = 200; /* kenji suzuki */
-
- unsigned int cur_seekptr = 0; /* 現在のインデックスのファイルポインタ先頭 */
- unsigned int nex_seekptr = 0; /* 1つ後のインデックスのファイルポインタ先頭 */
-
- unsigned int rirekitbl[ 258 ]; /* 履歴テーブル */
- int rirekimax;
-
- char e_key = 0; /* EPWINGタイプなら=1 */
-
- /*
- * 描画ルーチンリスト
- */
- proc_list_t
- mainDraw = {MainDraw, NULL /* リスト終了 */};
-
- /*
- * ウインドウ定義
- */
- window_t mainWin = {
- &mainDraw, (window *) NULL, (window *) -1, {0, 0, MAIN_DX, MAIN_DY},
- "\@Untitled", 0, (MAIN_ID << 4) + MAIN_OPT, 0b0001
- };
-
-
- /*
- * 各種Methodの内容定義
- */
- /*
- m__t
- */
- m_control_t cprev = {{0 , 0, 0 + 6*6 + X_STDBTN, 0 + DY_STDBTN}, 0, 0, 1, 0, "\@▲"},
- cnext = {{48, 0, 48 + 6*6 + X_STDBTN, 0 + DY_STDBTN}, 0, 0, 1, 0, "\@▼"};
-
- /*
- * Method, Method Group定義
- */
- method_t
- mNext = {NULL, m_STDBTN, &cnext, DispNext},
- mPrev = {NULL, m_STDBTN, &cprev, DispPrev},
- *methods[] = {&mNext , &mPrev , NULL};
-
- /*
- * Jobの定義
- */
- /*
- job_t
- */
-
- /*
- グラフィックインデックス内のサーチ
- 1f32~1f52の後に続く6バイトは、次のインデックスへリンクするポインタ
- 1f33~1f63の後に続く8バイトは、意味が判らない というわけで、何もしない
- 1f42~1f62の後に続く6バイトは、意味が判らない というわけで、何もしない
- */
- /* int search_graphicindex( unsigned int page , unsigned int offset ) */
- int search_graphicindex( unsigned int filepos )
- {
- unsigned short c , flg;
- unsigned int indexpage , indexoff;
- long position;
-
- DOSSEEK( cdfile , filepos, SEEK_SET );
-
- /* DOSREAD( cdfile , &c , sizeof( unsigned short ) ); */
- /* if( (c&0xffff) == 0x1f09 )
- {
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- } else {
- DOSSEEK( cdfile , -2 , SEEK_CUR );
- };
- */
- position = filepos;
- flg = 0;
- for (;;) {
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=2;
- if ((c&0xff00)==0x1f00) {
- switch (c&0xff) {
- case 0x45:
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=2;
- break;
- case 0x65:
- return( 0 );
- case 0x42:
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=4;
- break;
- case 0x62:
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=6;
- break;
-
- case 0x31:
- /* グラフィック用画面のサイズ? */
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &gra_x , sizeof( unsigned short ) );
- DOSREAD( cdfile , &gra_y , sizeof( unsigned short ) );
- gra_x = conv_hex( gra_x );
- gra_y = conv_hex( gra_y );
- position+=6;
- break;
- case 0x51:
- /* */
- DOSREAD( cdfile , &indexpage , sizeof( unsigned int ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- indexoff = (int)c;
- position+=6;
- indexpage = conv_hex( indexpage );
- indexoff = conv_hex( indexoff );
-
- showgraph( gra_x , gra_y , (indexpage-1)*0x800+indexoff );
- DOSSEEK( cdfile , position , SEEK_SET ); /* ファイルポインタを元に戻す */
- break;
- case 0x32:
- /* テキスト用画面のサイズ? */
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=4;
- break;
- case 0x52:
- /* 次へのポインタ */
- DOSREAD( cdfile , &indexpage , sizeof( unsigned int ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- indexoff = (int)c;
- indexpage = conv_hex( indexpage );
- indexoff = conv_hex( indexoff );
- nex_seekptr = (indexpage-1)*0x800+indexoff;
- position += 6;
- break;
- case 0x33:
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=4;
- break;
- case 0x53:
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- DOSREAD( cdfile , &c , sizeof( unsigned short ) );
- position+=8;
- break;
- case 0x34:
- break;
- case 0x54:
- break;
- default:
- break;
- }
- }
- }
- }
-
- /* グラフィックイメージの表示 */
- int showgraph( unsigned short x , unsigned short y , unsigned int filepos )
- {
- ri = (rectImg *)_ULMALLOC( ((x/8)*y*2)+32 ); /* イメージを格納するメモリの確保 64byte余裕をもたせた */
- if( ri == NULL )
- {
- return( -1 );
- };
- /* printf( "graph = %x %x\n" , page , offset ); */
- /* レクタングルイメージの第1ページ、第2ページにデータをセット(黒で表示) */
- DOSSEEK( cdfile , filepos , SEEK_SET );
- DOSREAD( cdfile , &(*ri).data , (x/8)*y );
-
- memcpy( &((*ri).data)+(x/8*y) , &(*ri).data , (x/8)*y );
-
- (*ri).bounds.top = 0;
- (*ri).bounds.left = 0;
- (*ri).bounds.right = x;
- (*ri).bounds.bottom = y;
-
- return( 0 );
- }
-
- /* BCDコードを16進に変換 */
- unsigned int conv_hex( unsigned int data )
- {
- unsigned int data16;
- unsigned char hhh,hhl,hlh,hll;
- unsigned char lhh,lhl,llh,lll;
-
- data16 = 0;
-
- hhh = (data & 0xf0000000) >> 28;
- hhl = (data & 0x0f000000) >> 24;
- hlh = (data & 0x00f00000) >> 20;
- hll = (data & 0x000f0000) >> 16;
- lhh = (data & 0x0000f000) >> 12;
- lhl = (data & 0x00000f00) >> 8;
- llh = (data & 0x000000f0) >> 4;
- lll = (data & 0x0000000f);
-
- data16 = hhh*10000000 + hhl*1000000 + hlh*100000 + hll*10000;
- data16 = data16 + lhh*1000 + lhl*100 + llh*10 + lll;
-
- return( data16 );
- }
-
- /* 履歴テーブル関係 */
- int init_rirekitbl( void )
- {
- rirekitbl[ 0 ] = 0;
- rirekimax = 0;
-
- return( 0 );
- };
-
- int push_rireki( int rireki )
- {
- if( rirekimax == 256 )
- {
- return( -1 );
- };
-
- rirekimax++;
- rirekitbl[ rirekimax ] = rireki;
- rirekitbl[ rirekimax+1 ] = 0;
-
- return( 0 );
- };
-
- /*
- * 描画関数定義
- */
- int MainDraw()
- {
- rect winside;
- point_t wsize;
-
- if( nex_seekptr != 0 )
- {
- AwakeMethod( &mNext , 1 );
- } else {
- SleepMethod( &mNext , 1 );
- };
- if( rirekimax > 1 )
- {
- AwakeMethod( &mPrev , 1 );
- } else {
- SleepMethod( &mPrev , 1 );
- };
-
- GetWinInside(&mainWin, &winside);
- wsize = ULSizeOfRect(&winside);
- ULD3LineH(Point_t(0, 20), Point_t(Pt_x(wsize), 0), 1);
- if( ri != NULL )
- {
- /* アクセスページセット */
- GMAPage (0b0011);
-
- GMPutRImg( ri , 21 );
- };
-
- return 0;
- }
-
-
- /* tsugi */
- int DispNext()
- {
- if( nex_seekptr != 0 )
- {
- if(( rirekimax > 0 ) && ( rirekimax <= 256 ))
- {
- push_rireki( nex_seekptr );
- cur_seekptr = nex_seekptr;
- nex_seekptr = 0;
- search_graphicindex( cur_seekptr );
- MainDraw( );
- /* } else {
- DMError( 1,"これより後方の画像は表示できません\n" );
- */ };
- };
-
- return( 1 );
- }
-
- /* mae */
- int DispPrev()
- {
- if( rirekimax > 1 )
- {
- cur_seekptr = rirekitbl[ rirekimax-1 ];
- rirekimax -= 1;
- nex_seekptr = 0;
- search_graphicindex( cur_seekptr );
- MainDraw( );
- /* } else {
- DMError( 1,"これより後方の画像は表示できません\n" );
- */ };
-
- return( 1 );
- }
-
-
- void MainLoop()
- {
- order_t order = {0};
- while (true) {
- order.ev = MayIHelpYou();
- switch (order.ev) {
- case EV_CLOSEALL:
- case EV_CLOSEWIN:
- return; /* 終了指令ならメインループ終了 */
- case EV_SAVE: /* 終了するのでセーブしなくてはいけない */
- case EV_ACTIVATE: /* アクティベイト event が起こった */
- case EV_OPENFILE: /* ファイルが開かれた */
- case EV_CLOSEFILE: /* ファイルクローズ */
- case EV_DELETEFILE: /* ファイルの削除 */
- case EV_CREATETSK: /* あるタスクの開始 */
- case EV_EXITTSK: /* あるタスクの終了 */
- case EV_UNDEFINED: /* 上で定義されていないSYSTEM12 event */
- continue; /* 無視する物は明示しておいた方が効率が良い? */
- default:
- ; /* ここでMethodの判定をする */
- }
- }
- }
-
- int main( int ac , char *av[] )
- {
- int i;
- char *ptr;
- unsigned int seekptr = 0;
- char *wintitle = NULL;
- char work[ 40 ];
- int linkflg;
-
- if( ac < 2 )
- {
- return( 0 );
- };
-
- /* コマンドラインオプションの読み取り */
- for (i = 1; i < ac; i++) {
- ptr = av[i];
- switch (*ptr) {
- case '/':
- case '-':
- ptr++;
- if ('t' == *ptr )
- {
- ptr++;
- seekptr = ULSTOX( ptr );
- cur_seekptr = seekptr;
- } else if ('f' == *ptr )
- {
- ptr++;
- cdfile = TSOpen( ptr , 0 );
- if( cdfile < 0 )
- {
- /* ULError_str( "Error ファイルがオープンできません path=\n" , ptr );
- */ return( 0 );
- };
- } else if ('n' == *ptr )
- {
- ptr++;
- wintitle = ptr;
- } else if ('e' == *ptr )
- {
- e_key = 1;
- } else if ('x' == *ptr )
- {
- ptr++;
- gra_x = ULSTOX( ptr );
- } else if ('y' == *ptr )
- {
- ptr++;
- gra_y = ULSTOX( ptr );
- };
- break;
- }
- }
- /* DOSSEEK( cdfile , seekptr , SEEK_SET ); */
-
- if( e_key == 1 )
- {
- showgraph( gra_x , gra_y , seekptr );
- } else {
- search_graphicindex( seekptr );
- };
-
- mainWin.bound.right = gra_x;
- mainWin.bound.bottom = gra_y+21;
-
- if (OpenWindow(&mainWin, -1) < 0) {
- DMError( 1, "ウインドウさえ開きません" );
- _ULFREE( ri );
- TSClose( cdfile );
- return 1;
- }; /* ウインドウを開く */
-
- ChainMethodIn(&mainWin, methods); /* Methodを登録する */
-
- init_rirekitbl( );
- push_rireki( seekptr );
-
- if( wintitle != NULL )
- {
- strcpy( work , "画像 [" );
- strcat( work , wintitle );
- strcat( work , "]" );
- ULStrZTOLZ( work ); /* LASCIIを作る */
- WMTitleSet( mainWin.wptr , work );
- };
- MainLoop(); /* メインループ */
- UnchainMethod(); /* Methodを登録から外す */
- CloseWindow(&mainWin); /* ウインドウを閉じる */
- _ULFREE( ri );
- if( cdfile != 0 )
- {
- TSClose( cdfile );
- };
-
- return( 0 );
- }